<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*,java.sql.*"
    pageEncoding="UTF-8"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
科室得分情况(月表)
</title>
<link rel="stylesheet" href="./css/table.css" type="text/css">
</head>
<%
	request.setCharacterEncoding("UTF-8"); 
	response.setContentType("text/html;charset=UTF-8");
	
	int year = 0;
	int month = 0;
	int kaohe_id = 0;
	if(request.getParameter("year") != null && !request.getParameter("year").equals("undefined")){
		year = Integer.valueOf(request.getParameter("year")).intValue();
	}
	if(request.getParameter("month") != null && !request.getParameter("month").equals("undefined")){
		month = Integer.valueOf(request.getParameter("month")).intValue();
	}
	if(request.getParameter("kaohe_id") != null && !request.getParameter("kaohe_id").equals("undefined")){
		kaohe_id = Integer.valueOf(request.getParameter("kaohe_id")).intValue();
	}
	
	
	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
	Statement stmt;
	ResultSet rs;
	
	Connection conn=java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=PZSYYDB","performance","performance");

%>
<body>


<br>
<div id="topTitle">
科室得分情况(月表)
</div>
<br>
<div id="biaoti">
年份:
<select id="year">
	<option value="2012">2012</option>
	<option value="2013">2013</option>
	<option value="2014">2014</option>
	<option value="2015">2015</option>
	<option value="2016">2016</option>
	<option value="2017">2017</option>
</select>
&nbsp;&nbsp;&nbsp;
月份:
<select id="month">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
</select>
&nbsp;&nbsp;&nbsp;
查看科室:
<select id="kaohe">
	<!--option value="all">-全部-</option-->
	<%	
	String 	sql = "select d.id,td.name+'-'+d.name from "+
	" t_sys_stat_department as d"+
	" left join DICT_DUTY_TYPE as td on td.id = d.duty_id where d.id != 1 order by d.name,td.name";
	stmt =  conn.createStatement();
	rs =stmt.executeQuery(sql);
	while(rs.next()){
		%><option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option><%
	}
	
	%>
</select>
<input type="button" value="提交" onclick="return submit();"/>
</div>



<table class="t1">
	
		<%
			int manfenSum = 0;
			int pingfenSum = 0;
			System.out.println("..................."+kaohe_id);
			if(kaohe_id != 0)
			{
				%>
		<thead>
			<tr>
				<td>编号</td><td>指标</td><td>评分标准</td><td>满分</td><td>实际得分</td>
			</tr>
		</thead>
		<tbody>
				<%				
				sql = "select kpi_id,item_name,description,point,"+
				"	case when detail_type = 2 then "+
				"	(point - (select sum(dv.score) from KPI_DETAIL_VALUE as dv"+
				"	where dv.year = "+year+" and dv.month = "+month+" "+
				"	and dv.parent_id = k.kpi_id and dv.kaohe_id = k.kaohe_id)"+
				"	)"+
				"	when detail_type != 2 then "+
				"	("+
				"	select score from KPI_VALUE as v where v.year = "+year+" and v.month = "+month+""+
				"	and v.kaohe_id = k.kaohe_id and v.kpi_id = k.kpi_id"+
				"	)"+
				"	else 0 end as defen,"+
				"	case when detail_type = 2 then "+
				"	(select sum(dv.value) from KPI_DETAIL_VALUE as dv"+
				"	where dv.year = "+year+" and dv.month = "+month+" "+
				"	and dv.parent_id = k.kpi_id and dv.kaohe_id = k.kaohe_id"+
				"	)"+
				"	when detail_type != 2 then "+
				"	("+
				"	select v.value from KPI_VALUE as v where v.year = "+year+" and v.month = "+month+""+
				"	and v.kaohe_id = k.kaohe_id and v.kpi_id = k.kpi_id"+
				"	)"+
				"	else 0 end as tijiao "+
				"	 from KPI_VS_ORGANIZATION as k"+
				"	where kaohe_id = "+kaohe_id+""+
				"	and standard_type = 0 order by kpi_id";
				System.out.println(sql);
				
				stmt =  conn.createStatement();
				rs =stmt.executeQuery(sql);
				while(rs.next()){
					if(rs.getString(4) != null && !rs.getString(4).equals("undefined")){
						manfenSum+=rs.getInt(4);
					}
					if(rs.getString(5) != null && !rs.getString(5).equals("undefined")){
						pingfenSum+=rs.getInt(5);
					}
					%><tr><td><%=rs.getString(1)%></td>
					<td><%=rs.getString(2)%></td>
					<td><%=rs.getString(3)%></td>
					<td><%=rs.getString(4)%></td>
					<td><%=rs.getString(5)%></td></tr><%
				}
			%>
		</tbody>
		<tfoot>
			<tr>
				<td>合计</td><td></td><td></td><td><%=manfenSum %></td><td><%=pingfenSum %></td>
			</tr>
		</tfoot>
			
			<%
			}
			rs.close();
			stmt.close();
			conn.close();	
		
		%>
	
</table>

<form id="searchForm" method="post" action="./m-001.jsp">
	<input type="hidden" name="year"/>
	<input type="hidden" name="month"/>
	<input type="hidden" name="kaohe_id"/>
</form>


<script type="text/javascript">
	var dt = new Date();
	
	window.onload = initData();
	
	function initData(){
		try{
			var y = <%=request.getParameter("year")%>;
			var m = <%=request.getParameter("month")%>;
			var kh_id = <%=request.getParameter("kaohe_id")%>;
			if(y == null && m == null){
				if(dt.getMonth() == 1){
					document.getElementById("year").options[dt.getYear()+1900-2013].selected = true;
					document.getElementById("month").options[11].selected = true;
				}else{
					document.getElementById("year").options[dt.getYear()+1900-2012].selected = true;
					document.getElementById("month").options[dt.getMonth()-1].selected = true;
				}
			}else{
				document.getElementById("year").options[parseInt(y)-2012].selected = true;
				document.getElementById("month").options[parseInt(m)-1].selected = true;
			}
			var kaoheV = document.getElementById("kaohe");
			for(var i = 0;i<kaoheV.options.length;i++)
			{
				if(kaoheV.options[i].value == kh_id)
				{
					kaoheV.options[i].selected = true;
					break;
				}
			}
		}catch(e){
			alert(e);
		}
	}
	function submit(){
		try{
			document.getElementById("searchForm").year.value=document.getElementById("year").value;
			document.getElementById("searchForm").month.value=document.getElementById("month").value;
			document.getElementById("searchForm").kaohe_id.value=document.getElementById("kaohe").value;//sel.options[sel.options.selectedIndex].value;
			document.getElementById("searchForm").submit();
		}catch(e){
			alert(e);
		}
	}

</script>

</body>



</html>